package edu.jmu.myshop.service.reg.controller;

import com.google.common.collect.Lists;
import edu.jmu.myshop.commons.domain.TbUser;
import edu.jmu.myshop.commons.dto.AbstractBaseResult;
import edu.jmu.myshop.commons.dto.BaseResultFactory;
import edu.jmu.myshop.commons.web.AbstractBaseController;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Wen
 */
@RestController
@RequestMapping(value = "test")
public class TestController extends AbstractBaseController<TbUser> {



    @GetMapping(value = "records/{id}")
    public AbstractBaseResult getById(HttpServletRequest request, @PathVariable long id) {
        if (id==1) {
            TbUser tbUser = new TbUser();
            tbUser.setId(1L);
            tbUser.setUsername("zhangsan");
            return success(tbUser);
        } else {
            return error(HttpStatus.UNAUTHORIZED.value(),"message",null);
        }


    }

    @GetMapping(value = "records")
    public AbstractBaseResult getList(HttpServletRequest request) {
        List<TbUser> list = Lists.newArrayList();
        TbUser tbUser = new TbUser();
        tbUser.setId(1L);
        tbUser.setUsername("zhangsan");
        list.add(tbUser);
        TbUser tbUser1 = new TbUser();
        tbUser1.setId(2L);
        tbUser1.setUsername("zhangsan1");
        list.add(tbUser1);
        return success(2,10,list);
    }
}